package com.shujia.day18;

/*
    使用继承Thread类来实现售票案例
 */
class Window extends Thread{
    static int tickets = 100;

    @Override
    public void run() {
//        int tickets = 100;
        while (true){
            if(tickets>0){
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("当前 " + getName()+" 正在出售第 "+(tickets--)+" 张票");
            }
        }
    }
}

public class SellTicketsDemo1 {
    public static void main(String[] args) {
        Window w1 = new Window();
        Window w2 = new Window();
        Window w3 = new Window();

        w1.setName("窗口1");
        w2.setName("窗口2");
        w3.setName("窗口3");

        w1.start();
        w2.start();
        w3.start();
    }
}
